package com.renderplane;

import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;


public class renderplane extends Activity {

	static OpenGLRenderer2 renderer = new OpenGLRenderer2();
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
    	    	
    	// fullscreen 
        this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    	
        // init opengl
 		GLSurfaceView view = new GLSurfaceView(this);
   		view.setRenderer(renderer);
   		setContentView(view);
    }
    
    public boolean onKeyDown(int keyCode, KeyEvent event)  {
        if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
            renderer.centerKey();
            return true;
        }
        
        if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
        	renderer.modifyPitch(-1);
            return true;
        }        
        
        if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
        	renderer.modifyPitch(1);
            return true;
        }
        
        if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
        	renderer.modifyAzimuth(1);
            return true;
        }
        
        if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
        	renderer.modifyAzimuth(-1);
            return true;
        }
        
        if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        	renderer.modifyRoll(1);
            return true;
        }
        
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        	renderer.modifyRoll(-1);
            return true;
        }
        
        // default
        return super.onKeyDown(keyCode, event);
    }
}
